package com.example.blog.service;

import com.example.blog.dao.ArticleDao;
import com.example.blog.pojo.Article;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @author tengfei wang
 * @version 1.0
 * @date Created in 2020/9/21
 */
@Service
@Slf4j
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Override
    public Page<Article> getArticleWithPage(Integer page, Integer size) {
        log.info("page is {}, size is {}", page, size);
        if (page <= 0) {
            page = 1;
        }
        Pageable pageRequest = PageRequest.of(page - 1, size);
        return articleDao.findAll(pageRequest);
    }
}
